<?php

class ItemsController extends AppController
{
	var $name = 'Items';
	var $helpers = array('Html', 'Form', 'Cache');
	
	function index()
	{
		$this->Item->recursive = 1;
		
		$Items = $this->Item->find('all',
         array('fields' =>
                array('Item.prompt')
                  )
            );
      $this->set('Items', $Items);
	}

	function add($survey_id = '')
	{
		$this->set('survey_id', $survey_id);
		
		$items = $this->Item->findAllBySurveyId($survey_id);
		
		$this->set(compact('items'));
		
		// these lines for testing
		
		$this->Item->create();
		
		if($this->Item->save($this->data))
		{
			$this->Session->setFlash('Item saved');
			//$this->redirect('http://www.yahoo.com', null, true);
			$this->redirect("/items/add/$survey_id");        //.$this->params['pass']/*, null, true*/);
			//$this->redirect('/items/add/'.$this->params['pass']/*, null, true*/);
			//$this->redirect(array('controller' => 'items', 'action' => 'add', 'pass' => $survey_id));
		}
		else
		{
			$this->Session->setFlash('not saved');
		}
	}
	
   /*
   function post_add()
   {
     //$this->Item->create();
     $this->Item->save($this->data);
	 $this->redirect(array('controller'=>'surveys', 'action'=>'view'));
     exit();
   }
   */
   function show_table()
   {
	pr($this->Item->schema());
   }
   
   function new_item($survey_id = '')
   {
   }
   
}

?>
